
import service from './axios.js'
// 6.1、封装get请求导出
/**
 * 封装get方法
 * @param url
 * @param data
 * @returns {Promise}
 */

export function getApi(url) {
    return new Promise((resolve, reject) => {
        service.get(url)
        .then(response => {
            resolve(response);
        })
        .catch(err => {
            reject(err)
        })
    })
}

// 6.2、封装post请求导出
/**
 * 封装post请求
 * @param url
 * @param data
 * @returns {Promise}
 */

export function postApi(url, data = {}) {
    return new Promise((resolve, reject) => {
        service.post(url, data)
        .then(response => {
            resolve(response);
        }, err => {
            reject(err)
        })
    }).catch((e) => {});
}

// 6.3、封装delete
/**
 * 封装post请求
 * @param url
 * @param data
 * @returns {Promise}
 */

export function deleteApi(url, data) {
    console.log(url, data,"shanchu");
    return new Promise((resolve, reject) => {
        service.delete(url+'/'+data)
            .then(response => {
            resolve(response);
        }, err => {
            reject(err)
        })
    })
}

// 6.4、封装put
/**
 * 封装post请求
 * @param url
 * @param data
 * @returns {Promise}
 */

export function putApi(url,data = {}) {
    console.log(url, data ,"1111111111");
 
    return new Promise((resolve, reject) => {
        service.put(url+'/'+data.id, data.data)
        .then(response => {
            resolve(response);
        }, err => {
            reject(err)
        })
    })
}
